import * as types from '../../mutation-types/create-adv/index';

const state = {
    activeStep: "1",
    createdStep: "1",
    adverPlan: "",
    adverName: "",
    adverUrl: "",
    audienceInfo: {},
    audienceTabs: [],
    homepageList: [],
    budgetSchedule: null,
    adCreate: null,
    adPlatform: "",
    audienceCountTips: {
        pcCount: "",
        mobileCount: "",
        allCount: ""
    },
    ggAudienceCountTips: {
        click:"",
        cost:"",
        impressions:""
    },
    adStepList: [{
        step: "1",
        created: false, //是否完成本步编辑
        click: true, //是否可点击
        style: "li-active", //状态：li-default:默认；li-created：已创建；li-click：可点击；li-actvie：选中状态
        title: "广告目标",
        info: "广告目标",
        icon: 'el-icon-arrow-right' //图标分为√和>
    }, {
        step: "2",
        created: false,
        click: false,
        style: "li-default",
        title: "选择受众",
        info: "覆盖用户",
        icon: 'el-icon-arrow-right'
    }, {
        step: "3",
        created: false,
        click: false,
        style: "li-default",
        title: "预算和排期",
        info: "",
        icon: 'el-icon-arrow-right'
    }, {
        step: "4",
        created: false,
        click: false,
        style: "li-default",
        title: "广告制作",
        info: "",
        icon: 'el-icon-arrow-right'
    }],
    editAudienceForm: {
        name: null, //受众名称
        nameList: {}, //选择的受众信息
        addr: { //位置
            include: [], //包括
            exclude: [] //不包括
        },
        language: [], //语言
        gender: null, //性别
        age: { //年龄
            start: "21",
            end: "65"
        },
        position: { //细分定位
            include: [],
            exclude: []
        },
        relationship: null, //关系1/2/3 CONNECTION
        checkHomePage: [], //已选主页{"value":"主页1"}
        keywords: { //关键词
            include: [], //包括
            exclude: [] //不包括
        },
        reach: null
    },
    adverLayout: {
        LayoutType: "auto", //版位：自动auto,编辑edit
        device: 'all', //设备all/pc/mb
    },
    budgetAmount: {
        amountMin: null,//最小建议竞价
        amountMax: null,//最大建议竞价
        amountMedian: null//建议竞价
    },
    stepBudget: 6,
    stepSchedule: null,
    stepClickCost: null,
    stepAdTest: null,
    editBudgetData:{
        bidAmount:null,
        budgetAmount:null,
        endTime:null,
        isAutoBid:true,
        isDailyDelivery:null,
        startTime:null,
        timeQuantumList:[],
    },
    esimate: {},
    isAdPostDone: false,
    adErrorData: []
};

const mutations = {
    [types.ACTIVE_STEP](state, {step}) {
        state.activeStep = step;
        let list = state.adStepList;
        for (let i = 0; i < list.length; i++) {
            if (list[i].style == "li-active") {
                if (list[i].created && list[i].click) {
                    list[i].style = "li-created"
                    list[i].icon = "el-icon-check"
                } else if (!list[i].created && list[i].click) {
                    list[i].style = "li-click"
                    list[i].icon = "el-icon-arrow-right"
                }
            }
            if (list[i].step == step) {
                list[i].click = true;
                list[i].icon = "el-icon-arrow-right";
                list[i].style = "li-active";
            }
        }
    },
    [types.AD_PLATFORM](state, {item}) {
        state.adPlatform = item;
    },
    [types.EDIT_BUDGET_DATA](state, {item}) {
        state.editBudgetData = item;
    },
    [types.AUDIENCE_TABS](state, {item}) {
        state.audienceTabs = item;
    },
    [types.HOMEPAGE_LIST](state, {item}) {
        state.homepageList = item;
    },

    [types.CREATED_STEP](state, {step}) {
        state.createdStep = step;
    },
    [types.INIT_AUDIENCE](state, {init}) {
        state.editAudienceForm = {
            name: null, //受众名称
            nameList: {}, //选择的受众信息
            addr: { //位置
                include: [], //包括
                exclude: [] //不包括
            },
            language: [], //语言
            gender: null, //性别
            age: { //年龄
                start: "21",
                end: "65"
            },
            position: { //细分定位
                include: [],
                exclude: []
            },
            relationship: null, //关系1/2/3 CONNECTION
            checkHomePage: [], //已选主页{"value":"主页1"}
            keywords: { //关键词
                include: [], //包括
                exclude: [] //不包括
            },
            reach: null
        }
    },
    [types.ADSTEP_LIST](state, {item}) {
        state.adStepList = item;
    },
    [types.AUDIENCE_INFO](state, {item}) {
        state.audienceInfo = item;
    },

    [types.AUDIENCE_COUNT_TIPS](state, {item}) {
        state.audienceCountTips = item;
    },

    [types.GGAUDIENCE_COUNT_TIPS](state, {item}) {
        state.ggAudienceCountTips = item;
    },

    [types.ADVER_PLAN](state, {item}) {
        state.adverPlan = item;
        if(item == '主页赞'){
            state.adverLayout.device = 'pc'
        }else{
            state.adverLayout.device = 'all'
        }
    },
    [types.ADVER_NAME](state, {item}) {
        state.adverName = item;
    },
    [types.ADVER_URL](state, {item}) {
        state.adverUrl = item;
    },

    [types.ADSTEP_LIST_CREATED](state, {item}) {
        let list = state.adStepList;
        for (let i = 0; i < list.length; i++) {
            if (list[i].style == "li-active") {
                if (list[i].created && list[i].click) {
                    list[i].style = "li-created"
                    list[i].icon = "el-icon-check"
                } else if (!list[i].created && list[i].click) {
                    list[i].style = "li-click"
                    list[i].icon = "el-icon-arrow-right"
                }
            }
            for (let n = 0; n < item.length; n++) {
                if (list[i].step == item[n].step) {
                    list[i].click = item[n].click;
                    list[i].created = item[n].created;
                    list[i].icon = item[n].icon;
                    list[i].info = item[n].info;
                    list[i].style = item[n].style;
                }
            }
        }
    },
    [types.AD_CREATE](state, {data}) {
        state.adCreate = data
    },
    [types.BUDGET_SCHEDULE](state, {data}) {
        state.budgetSchedule = data
    },
    [types.BUDGET_AMOUNT](state, {data}) {
        state.budgetAmount = data
    },
    [types.STEP_BUDGET](state, {data}) {
        state.stepBudget = data
    },
    [types.STEP_SCHEDULE](state, {data}) {
        state.stepSchedule = data
    },
    [types.STEP_CLICKCOST](state, {data}) {
        state.stepClickCost = data
    },
    [types.STEP_ADTEST](state, {data}) {
        state.stepAdTest = data
    },
    [types.INIT_STEP](state, {step}) {
        state.adStepList = [{
            step: "1",
            created: false, //是否完成本步编辑
            click: true, //是否可点击
            style: "li-active", //状态：li-default:默认；li-created：已创建；li-click：可点击；li-actvie：选中状态
            title: "广告目标",
            info: "广告目标",
            icon: 'el-icon-arrow-right' //图标分为√和>
        }, {
            step: "2",
            created: false,
            click: false,
            style: "li-default",
            title: "选择受众",
            info: "覆盖用户",
            icon: 'el-icon-arrow-right'
        }, {
            step: "3",
            created: false,
            click: false,
            style: "li-default",
            title: "预算和排期",
            info: "",
            icon: 'el-icon-arrow-right'
        }, {
            step: "4",
            created: false,
            click: false,
            style: "li-default",
            title: "广告制作",
            info: "",
            icon: 'el-icon-arrow-right'
        }]
    },
    [types.GG_ESIMATE](state, {data}) {
        state.esimate = data
    },
    [types.ISADPOSTDONE](state, {data}) {
        state.isAdPostDone = data
    },
    [types.ADERRORDATA](state, {data}) {
        state.adErrorData = data
    }

};

export default {
    state,
    mutations
};